import cv2
import numpy as np
import math

# 图像大小
image_size = (640, 640)  # 宽和高为 640 像素
background_color = (255, 255, 255)  # 白色背景

# 创建空白图像
image = np.ones((image_size[1], image_size[0], 3), dtype=np.uint8) * 255

# 定义新的原点
origin = (320, 320)

# 定义点的范围和间隔
points = []

# 第一组点
start_point = (100, 100)
end_point = (500, 100)
spacing = 50
for x in range(start_point[0], end_point[0] + 1, spacing):
    points.append((x, start_point[1]))

# 第二组点
start_point = (100, 500)
end_point = (500, 500)
spacing = 50
for x in range(start_point[0], end_point[0] + 1, spacing):
    points.append((x, start_point[1]))

# 第三组点
start_point = (100, 400)
end_point = (500, 400)
spacing = 50
for x in range(start_point[0], end_point[0] + 1, spacing):
    points.append((x, start_point[1]))

# 绘制点
point_color = (255, 0, 255)  # 紫色
point_radius = 5  # 点的半径
for point in points:
    # 在图像上绘制点
    cv2.circle(image, point, point_radius, point_color, -1)

# 显示原点
cv2.circle(image, origin, 5, (0, 255, 0), -1)  # 绿色表示原点

# 保存图像
output_path = "output.png"
cv2.imwrite(output_path, image)

# 转换为极坐标
polar_coordinates = []  # 存储极坐标
for point in points:
    # 计算 r 和 theta
    dx = point[0] - origin[0]
    dy = point[1] - origin[1]
    r = math.sqrt(dx**2 + dy**2)  # 距离
    theta = math.atan2(dy, dx)  # 角度（弧度）
    polar_coordinates.append((r, theta))

# 打印极坐标结果
print("极坐标 (r, θ) 的结果：")
for i, (r, theta) in enumerate(polar_coordinates):
    print(f"点 {i + 1}: r = {r:.2f}, θ = {math.degrees(theta):.2f}°")  # 将弧度转换为角度
